﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ISSMoviePlex.BLL;
using ISSMoviePlex.DAL.Models;

namespace ISSMoviePlex.Admin.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            LoginModel admin = new LoginModel();
            admin.UserName = UserName.Text;
            admin.Password = Password.Text;
            admin.RememberMe = RememberMe.Checked;

            string errorMessage = string.Empty;

            AccountBLL accLogic = new AccountBLL();
            if (accLogic.Login(admin, AccountBLL.Role.Admin, ref errorMessage))
            {
                if (string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                {
                    Response.Redirect("~/Default.aspx");
                }
                else
	            {
                    Response.Redirect(Request.QueryString["ReturnUrl"]);
	            }                
            }
            else
            {
                FailureText.Text = errorMessage;
            }
        }
    }
}
